package com.heima.chengyuanbianliang;

import java.io.IOException;
import java.lang.reflect.Field;

public class ClassLocal03 {
    public static void main(String[] args) throws IOException, ClassNotFoundException, NoSuchFieldException {
//        Class aClass = Method01();
//        System.out.println(aClass);
//       Method02();
        method03();
        method04();
    }

    private static void method04() throws ClassNotFoundException {
        //返回所有public的和private成员变量
        Class class3 = Class.forName("com.heima.chengyuanbianliang.Student");
        Field[] declaredFields = class3.getDeclaredFields();
        for (Field declaredField : declaredFields) {
            System.out.println(declaredFields);
        }
    }

    private static void method03() throws ClassNotFoundException, NoSuchFieldException {
        //返回指定public的和private成员变量
        Class class3 = Class.forName("com.heima.chengyuanbianliang.Student");
        Field name = class3.getDeclaredField("name");
        System.out.println(name);
    }

    //返回指定的public的成员变量
    private static void Method02() throws ClassNotFoundException, NoSuchFieldException {
        Class class2 = Class.forName("com.heima.chengyuanbianliang.Student");
        Field field = class2.getField("id");
        System.out.println(field);
    }

    //返回所有public的成员变量
    private static Class Method01() throws ClassNotFoundException {
        Class aClass = Class.forName("com.heima.chengyuanbianliang.Student");
        Field[] fields = aClass.getFields();
        for (Field field : fields) {
            System.out.println(field);
        }
        return aClass;
    }
}
